package httpDemo;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* @author 作者 linweiqiang
* @version 创建时间：2017年11月13日 上午10:48:28
* 类说明
*/
public class RequestUrl {
	public static void main(String[] args) {
		String str= "";
		Pattern p = Pattern.compile("^data:.*?/([^;]*)");
		Matcher m = p.matcher(str);
		while(m.find()){
			System.out.println(m.group(0));
			System.out.println(m.group(1));
//			System.out.println(m.group(2));
		}
	}
	
	public String getHTML(String url){
		try {
			URL uri = new URL(url);
			URLConnection con = uri.openConnection();
			Map<String, List<String>> map = con.getHeaderFields();
			List<String> cookies = map.get("Set-Cookie");
			StringBuffer csb = new StringBuffer();
			for (String string : cookies) {
				csb.append(string);
			}
			System.out.println(csb.toString());
			InputStream in = con.getInputStream();
			byte[] buf = new byte[in.available()];
			int length = 0;
			StringBuffer sb = new StringBuffer();
			while((length=in.read(buf, 0, buf.length))>0){
				sb.append(new String(buf));
			}
			in.close();
			return sb.toString();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return null;
	}
}
